package com.bwie.mq;

import com.bwie.mapper.UserMapper;
import com.bwie.pojo.Store;
import com.bwie.pojo.User;
import com.bwie.utils.SendMsgUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 消费者消费消息
 */
public class MessageConsumer implements MessageListener {

    @Autowired
    private UserMapper userMapper ;

    @Override
    public void onMessage(Message message) {
        //创建一个消费者,消费队列中的数据
        byte[] body = message.getBody();
        //反序列化
        Store store = (Store) SerializationUtils.deserialize(body);

        //发送短信提示创建人 短信发送失败
        User user = userMapper.selectUser(store.getUserId());

        //定义信息
        String sendMessage = "短信发送失败,请重新发送";
        //发送短信
        String sendSms = SendMsgUtil.sendSms(user.getPhone(), sendMessage);
        System.out.println(sendSms);
    }
}
